unit PlayerUnit;

interface

uses common;

type
  Player = class
    function move(height, lastNumber, sortedNumber : integer; arr : array of integer) : integer;
  end;


implementation

{ Player }

function Player.move(height, lastNumber, sortedNumber : integer; arr : array of integer): integer;
var i, min, tmp, max: integer;

begin
  max:=arr[LastNumber+1];
  for i:=LastNumber+2 to LastNumber+4 do
    if (max<arr[i]) then
      max:=arr[i];
  min:=arr[0];
  tmp:=0;
  for i:=0 to LastNumber do
    if (min>arr[i]) then
    begin
      min:=arr[i];
      tmp:=i;
    end;
  if (height<max) and ( LastNumber+4<N-sortednumber) then
    move:=LastNumber+4
    else
    if (height>=min) then
      move:=tmp
    else
      move:=0;
end;

end.
